/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Aplicativo.java
 *
 * Created on 27/08/2011, 10:38:38
 */

package modules.enderecamento.gui;

import java.awt.Container;
import java.awt.Image;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.text.html.StyleSheet.BoxPainter;
import modules.enderecamento.facade.WMSFacade;
import modules.enderecamento.gui.custom.ImagemBorder;
import modules.enderecamento.gui.jpanel.PanelAlterarSenha;
import modules.enderecamento.gui.jpanel.PanelCadastroCargo;
import modules.enderecamento.gui.jpanel.PanelCadastroCliente;
import modules.enderecamento.gui.jpanel.PanelCadastroFornecedor;
import modules.enderecamento.gui.jpanel.PanelCadastroGruposAcesso;
import modules.enderecamento.gui.jpanel.PanelCadastroGruposProduto;
import modules.enderecamento.gui.jpanel.PanelCadastroPalete;
import modules.enderecamento.gui.jpanel.PanelCadastroProduto;
import modules.enderecamento.gui.jpanel.PanelCadastroRua;
import modules.enderecamento.gui.jpanel.PanelCadastroUsuario;
import modules.enderecamento.gui.jpanel.PanelCancelamentoEntrada;
import modules.enderecamento.gui.jpanel.PanelCancelamentoSaida;
import modules.enderecamento.gui.jpanel.PanelEntrada;
import modules.enderecamento.gui.jpanel.PanelEspacoFisico;
import modules.enderecamento.gui.jpanel.PanelLimparPalete;
import modules.enderecamento.gui.jpanel.PanelLimparRua;
import modules.enderecamento.gui.jpanel.PanelMoverPalete;
import modules.enderecamento.gui.jpanel.PanelMoverProduto;
import modules.enderecamento.gui.jpanel.PanelRelatorioAparelhosAcabados;
import modules.enderecamento.gui.jpanel.PanelRemoverPaleteVazio;
import modules.enderecamento.gui.jpanel.PanelSaida;
import modules.enderecamento.models.dto.Permissao;
import modules.enderecamento.security.WMSSession;
import modules.enderecamento.util.BoxPanel;
import modules.enderecamento.util.Funcoes;

/**
 *
 * @author Clezio
 */
public class Aplicativo extends javax.swing.JFrame {

    private JPanel panelCadastroFornecedor;
    private JPanel panelCadastroProduto;
    private JPanel panelCadastroGruposProduto;
    private JPanel panelCadastroPalete;
    private JPanel panelCadastroRua;
    private JPanel panelCadastroGruposAcesso;
    private JPanel panelCadastroUsuario;
    private JPanel panelEntrada;
    private JPanel panelSaida;
    private JPanel panelConsultaEspacoFisico;
    private JPanel panelAlterarSenha;
    private JPanel panelLimparPalete;
    private JPanel panelLimparRua;
    private JPanel panelMoverProduto;
    private JPanel panelMoverPalete;
    private JPanel panelRemoverPaleteVazio;
    private JPanel PanelCadastroCliente;
    private JPanel panelCancelamentoEntrada;
    private JPanel panelCancelamentoSaida;
    private JPanel panelCadastroCargo;
    private JPanel panelRelatorioAparelhosAcabados;
    /** Creates new form Aplicativo */
    public Aplicativo() {
        initComponents();

        ImageIcon icone = new ImageIcon("img/fundo.jpg");
        panelCadastroFornecedor = new PanelCadastroFornecedor();
        panelCadastroProduto = new PanelCadastroProduto();
        panelCadastroGruposProduto = new PanelCadastroGruposProduto();
        panelCadastroPalete = new PanelCadastroPalete();
        panelCadastroRua = new PanelCadastroRua();
        panelEntrada = new PanelEntrada();
        panelSaida = new PanelSaida();
        panelCadastroGruposAcesso = new PanelCadastroGruposAcesso();
        panelCadastroUsuario = new PanelCadastroUsuario();
        panelConsultaEspacoFisico = new PanelEspacoFisico();
        panelAlterarSenha = new PanelAlterarSenha();
        panelLimparPalete = new PanelLimparPalete();
        panelLimparRua = new PanelLimparRua();
        panelMoverProduto = new PanelMoverProduto();
        panelMoverPalete = new PanelMoverPalete();
        panelRemoverPaleteVazio = new PanelRemoverPaleteVazio();
        PanelCadastroCliente = new PanelCadastroCliente();
        panelCancelamentoEntrada = new PanelCancelamentoEntrada();
        panelCancelamentoSaida = new PanelCancelamentoSaida();
        panelCadastroCargo = new PanelCadastroCargo();
        panelRelatorioAparelhosAcabados = new PanelRelatorioAparelhosAcabados();

        panelMain.setBorder(new ImagemBorder(icone));

        if(WMSSession.getInstance().getUser()!=null){
            lbNomeUsuario.setText(WMSSession.getInstance().getUser().getNome());
            lbNomeUsuario.setIcon(new ImageIcon("img/user.png"));
        }else{
            lbNomeUsuario.setText("Usuário não encontrado");
        }
        lbNotificacao.setText("");
        analisaPermissaoMenu();
        WMSSession.getInstance().setAplicativo(this);
        
        try {
            setIconImage(Funcoes.showIcon("img/wms.ico", null).getImage());
        } catch (IOException ex) {
            Logger.getLogger(Aplicativo.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelMain = new modules.enderecamento.gui.custom.ImagePanel();
        jToolBar1 = new javax.swing.JToolBar();
        lbNomeUsuario = new modules.enderecamento.gui.custom.WMSLabel();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        lbNotificacao = new modules.enderecamento.gui.custom.WMSLabel();
        menuBar = new javax.swing.JMenuBar();
        mEstoque = new javax.swing.JMenu();
        iMEntrada = new javax.swing.JMenuItem();
        iMSaida = new javax.swing.JMenuItem();
        mCancelamento = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        mManutencao = new javax.swing.JMenu();
        imLimparPalete = new javax.swing.JMenuItem();
        imLimparRua = new javax.swing.JMenuItem();
        imMoverPalete = new javax.swing.JMenuItem();
        imMoverProduto = new javax.swing.JMenuItem();
        imRemoverPaleteVazio = new javax.swing.JMenuItem();
        mCadastro = new javax.swing.JMenu();
        iMCargos = new javax.swing.JMenuItem();
        iMClientes = new javax.swing.JMenuItem();
        iMFornecedores = new javax.swing.JMenuItem();
        iMGruposProdutos = new javax.swing.JMenuItem();
        iMPaletes = new javax.swing.JMenuItem();
        iMProdutos = new javax.swing.JMenuItem();
        iMRuas = new javax.swing.JMenuItem();
        mAdministrar = new javax.swing.JMenu();
        iMGruposAcessos = new javax.swing.JMenuItem();
        iMUsuarios = new javax.swing.JMenuItem();
        mConsulta = new javax.swing.JMenu();
        iMEspacoFisico = new javax.swing.JMenuItem();
        mRelatorios = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        mUtilitarios = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        mSair = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WMS - Endereçamento de Depósito");
        setResizable(false);

        panelMain.setBackground(new java.awt.Color(255, 255, 255));
        panelMain.setOpaque(false);

        javax.swing.GroupLayout panelMainLayout = new javax.swing.GroupLayout(panelMain);
        panelMain.setLayout(panelMainLayout);
        panelMainLayout.setHorizontalGroup(
            panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 798, Short.MAX_VALUE)
        );
        panelMainLayout.setVerticalGroup(
            panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 541, Short.MAX_VALUE)
        );

        jToolBar1.setBackground(new java.awt.Color(238, 238, 238));
        jToolBar1.setRollover(true);

        lbNomeUsuario.setText("wMSLabel1");
        jToolBar1.add(lbNomeUsuario);
        jToolBar1.add(jSeparator1);

        lbNotificacao.setForeground(new java.awt.Color(0, 0, 255));
        lbNotificacao.setText("wMSLabel2");
        jToolBar1.add(lbNotificacao);

        mEstoque.setMnemonic('E');
        mEstoque.setText("Estoque");

        iMEntrada.setMnemonic('E');
        iMEntrada.setText("Entrada");
        iMEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMEntradaActionPerformed(evt);
            }
        });
        mEstoque.add(iMEntrada);

        iMSaida.setMnemonic('S');
        iMSaida.setText("Saída");
        iMSaida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMSaidaActionPerformed(evt);
            }
        });
        mEstoque.add(iMSaida);

        mCancelamento.setMnemonic('C');
        mCancelamento.setText("Cancelamento");

        jMenuItem2.setMnemonic('E');
        jMenuItem2.setText("Registro de Entrada");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        mCancelamento.add(jMenuItem2);

        jMenuItem3.setMnemonic('S');
        jMenuItem3.setText("Registro de Saída");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        mCancelamento.add(jMenuItem3);

        mEstoque.add(mCancelamento);

        mManutencao.setMnemonic('M');
        mManutencao.setText("Manutenção");

        imLimparPalete.setText("Limpar Paletes");
        imLimparPalete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imLimparPaleteActionPerformed(evt);
            }
        });
        mManutencao.add(imLimparPalete);

        imLimparRua.setMnemonic('L');
        imLimparRua.setText("Limpar Ruas");
        imLimparRua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imLimparRuaActionPerformed(evt);
            }
        });
        mManutencao.add(imLimparRua);

        imMoverPalete.setMnemonic('M');
        imMoverPalete.setText("Mover Paletes");
        imMoverPalete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imMoverPaleteActionPerformed(evt);
            }
        });
        mManutencao.add(imMoverPalete);

        imMoverProduto.setMnemonic('M');
        imMoverProduto.setText("Mover Produtos");
        imMoverProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imMoverProdutoActionPerformed(evt);
            }
        });
        mManutencao.add(imMoverProduto);

        imRemoverPaleteVazio.setMnemonic('R');
        imRemoverPaleteVazio.setText("Remover Paletes Vazios");
        imRemoverPaleteVazio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imRemoverPaleteVazioActionPerformed(evt);
            }
        });
        mManutencao.add(imRemoverPaleteVazio);

        mEstoque.add(mManutencao);

        menuBar.add(mEstoque);

        mCadastro.setMnemonic('C');
        mCadastro.setText("Cadastro");

        iMCargos.setMnemonic('C');
        iMCargos.setText("Cargos");
        iMCargos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMCargosActionPerformed(evt);
            }
        });
        mCadastro.add(iMCargos);

        iMClientes.setMnemonic('C');
        iMClientes.setText("Clientes");
        iMClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMClientesActionPerformed(evt);
            }
        });
        mCadastro.add(iMClientes);

        iMFornecedores.setMnemonic('F');
        iMFornecedores.setText("Fornecedores");
        iMFornecedores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMFornecedoresActionPerformed(evt);
            }
        });
        mCadastro.add(iMFornecedores);

        iMGruposProdutos.setMnemonic('G');
        iMGruposProdutos.setText("Grupos de Produtos");
        iMGruposProdutos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMGruposProdutosActionPerformed(evt);
            }
        });
        mCadastro.add(iMGruposProdutos);

        iMPaletes.setMnemonic('P');
        iMPaletes.setText("Palete");
        iMPaletes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMPaletesActionPerformed(evt);
            }
        });
        mCadastro.add(iMPaletes);

        iMProdutos.setMnemonic('P');
        iMProdutos.setText("Produtos");
        iMProdutos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMProdutosActionPerformed(evt);
            }
        });
        mCadastro.add(iMProdutos);

        iMRuas.setMnemonic('R');
        iMRuas.setText("Ruas");
        iMRuas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMRuasActionPerformed(evt);
            }
        });
        mCadastro.add(iMRuas);

        menuBar.add(mCadastro);

        mAdministrar.setMnemonic('A');
        mAdministrar.setText("Administrar");

        iMGruposAcessos.setMnemonic('G');
        iMGruposAcessos.setText("Grupos de Acessos");
        iMGruposAcessos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMGruposAcessosActionPerformed(evt);
            }
        });
        mAdministrar.add(iMGruposAcessos);

        iMUsuarios.setMnemonic('U');
        iMUsuarios.setText("Usuários");
        iMUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMUsuariosActionPerformed(evt);
            }
        });
        mAdministrar.add(iMUsuarios);

        menuBar.add(mAdministrar);

        mConsulta.setMnemonic('C');
        mConsulta.setText("Consultas");

        iMEspacoFisico.setMnemonic('O');
        iMEspacoFisico.setText("Ocupação (Palete/Rua)");
        iMEspacoFisico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iMEspacoFisicoActionPerformed(evt);
            }
        });
        mConsulta.add(iMEspacoFisico);

        menuBar.add(mConsulta);

        mRelatorios.setMnemonic('R');
        mRelatorios.setText("Relatórios");

        jMenuItem4.setMnemonic('P');
        jMenuItem4.setText("Posição do estoque");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        mRelatorios.add(jMenuItem4);

        menuBar.add(mRelatorios);

        mUtilitarios.setMnemonic('U');
        mUtilitarios.setText("Utilitários");
        mUtilitarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mUtilitariosActionPerformed(evt);
            }
        });

        jMenuItem1.setMnemonic('A');
        jMenuItem1.setText("Alterar Senha");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mUtilitarios.add(jMenuItem1);

        menuBar.add(mUtilitarios);

        mSair.setMnemonic('S');
        mSair.setText("Sair");
        mSair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mSairMouseClicked(evt);
            }
        });
        mSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mSairActionPerformed(evt);
            }
        });
        menuBar.add(mSair);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE)
            .addComponent(panelMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(panelMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-808)/2, (screenSize.height-634)/2, 808, 634);
    }// </editor-fold>//GEN-END:initComponents

    private void iMFornecedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMFornecedoresActionPerformed
        adicionarPaineisInFrame(panelCadastroFornecedor);
    }//GEN-LAST:event_iMFornecedoresActionPerformed

    private void mSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSairActionPerformed
        
    }//GEN-LAST:event_mSairActionPerformed

    private void iMProdutosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMProdutosActionPerformed
        adicionarPaineisInFrame(panelCadastroProduto);
    }//GEN-LAST:event_iMProdutosActionPerformed

    private void mSairMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mSairMouseClicked
        WMSSession.getInstance().getTelaLogin().show();
        dispose();
        //System.exit(0);
    }//GEN-LAST:event_mSairMouseClicked

    private void iMGruposProdutosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMGruposProdutosActionPerformed
        adicionarPaineisInFrame(panelCadastroGruposProduto);
    }//GEN-LAST:event_iMGruposProdutosActionPerformed

    private void iMPaletesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMPaletesActionPerformed
        adicionarPaineisInFrame(panelCadastroPalete);
    }//GEN-LAST:event_iMPaletesActionPerformed

    private void iMRuasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMRuasActionPerformed
        adicionarPaineisInFrame(panelCadastroRua);
    }//GEN-LAST:event_iMRuasActionPerformed

    private void iMEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMEntradaActionPerformed
        adicionarPaineisInFrame(panelEntrada);
    }//GEN-LAST:event_iMEntradaActionPerformed

    private void iMSaidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMSaidaActionPerformed
        adicionarPaineisInFrame(panelSaida);
    }//GEN-LAST:event_iMSaidaActionPerformed

    private void iMGruposAcessosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMGruposAcessosActionPerformed
        adicionarPaineisInFrame(panelCadastroGruposAcesso);
    }//GEN-LAST:event_iMGruposAcessosActionPerformed

    private void iMUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMUsuariosActionPerformed
        adicionarPaineisInFrame(panelCadastroUsuario);
    }//GEN-LAST:event_iMUsuariosActionPerformed

    private void iMEspacoFisicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMEspacoFisicoActionPerformed
        adicionarPaineisInFrame(panelConsultaEspacoFisico);
    }//GEN-LAST:event_iMEspacoFisicoActionPerformed

    private void mUtilitariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mUtilitariosActionPerformed

    }//GEN-LAST:event_mUtilitariosActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        adicionarPaineisInFrame(panelAlterarSenha);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void imLimparPaleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imLimparPaleteActionPerformed
        adicionarPaineisInFrame(panelLimparPalete);
    }//GEN-LAST:event_imLimparPaleteActionPerformed

    private void imLimparRuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imLimparRuaActionPerformed
        adicionarPaineisInFrame(panelLimparRua);
    }//GEN-LAST:event_imLimparRuaActionPerformed

    private void imMoverProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imMoverProdutoActionPerformed
        adicionarPaineisInFrame(panelMoverProduto);
    }//GEN-LAST:event_imMoverProdutoActionPerformed

    private void imMoverPaleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imMoverPaleteActionPerformed
        adicionarPaineisInFrame(panelMoverPalete);
    }//GEN-LAST:event_imMoverPaleteActionPerformed

    private void imRemoverPaleteVazioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imRemoverPaleteVazioActionPerformed
        adicionarPaineisInFrame(panelRemoverPaleteVazio);
    }//GEN-LAST:event_imRemoverPaleteVazioActionPerformed

    private void iMClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMClientesActionPerformed
        adicionarPaineisInFrame(PanelCadastroCliente);
    }//GEN-LAST:event_iMClientesActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        adicionarPaineisInFrame(panelCancelamentoEntrada);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        adicionarPaineisInFrame(panelCancelamentoSaida);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void iMCargosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iMCargosActionPerformed
        adicionarPaineisInFrame(panelCadastroCargo);
    }//GEN-LAST:event_iMCargosActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        adicionarPaineisInFrame(panelRelatorioAparelhosAcabados);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Aplicativo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem iMCargos;
    private javax.swing.JMenuItem iMClientes;
    private javax.swing.JMenuItem iMEntrada;
    private javax.swing.JMenuItem iMEspacoFisico;
    private javax.swing.JMenuItem iMFornecedores;
    private javax.swing.JMenuItem iMGruposAcessos;
    private javax.swing.JMenuItem iMGruposProdutos;
    private javax.swing.JMenuItem iMPaletes;
    private javax.swing.JMenuItem iMProdutos;
    private javax.swing.JMenuItem iMRuas;
    private javax.swing.JMenuItem iMSaida;
    private javax.swing.JMenuItem iMUsuarios;
    private javax.swing.JMenuItem imLimparPalete;
    private javax.swing.JMenuItem imLimparRua;
    private javax.swing.JMenuItem imMoverPalete;
    private javax.swing.JMenuItem imMoverProduto;
    private javax.swing.JMenuItem imRemoverPaleteVazio;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private modules.enderecamento.gui.custom.WMSLabel lbNomeUsuario;
    private modules.enderecamento.gui.custom.WMSLabel lbNotificacao;
    private javax.swing.JMenu mAdministrar;
    private javax.swing.JMenu mCadastro;
    private javax.swing.JMenu mCancelamento;
    private javax.swing.JMenu mConsulta;
    private javax.swing.JMenu mEstoque;
    private javax.swing.JMenu mManutencao;
    private javax.swing.JMenu mRelatorios;
    private javax.swing.JMenu mSair;
    private javax.swing.JMenu mUtilitarios;
    private javax.swing.JMenuBar menuBar;
    private modules.enderecamento.gui.custom.ImagePanel panelMain;
    // End of variables declaration//GEN-END:variables

    private void adicionarPaineisInFrame(JPanel panel) {
        addDefineLayoutPanel(panel);
    }
    
    private void addDefineLayoutPanel(JPanel panel){
        Container container = getContentPane();
        GroupLayout layout = new javax.swing.GroupLayout(container);
        removePanel();
        java.awt.Dimension screenSize = getSize();
        int x = (screenSize.width - (int)panel.getPreferredSize().getWidth())/2;
        int y = (screenSize.height - (int)panel.getPreferredSize().getHeight())/2 - 50;
        if(y < 0){
            y = 0;
        }
        if(x < 0){
            x = 0;
        }

        container.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(x, x, x)
                .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(215, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
            .addGroup(layout.createSequentialGroup()
                .addGap(y, y, y)
                .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(143, Short.MAX_VALUE))
        );
    }

    private void removePanel() {
        remove(panelCadastroFornecedor);
        remove(panelCadastroProduto);
        remove(panelCadastroGruposProduto);
        remove(panelCadastroPalete);
        remove(panelCadastroRua);
        remove(panelEntrada);
        remove(panelSaida);
        remove(panelCadastroGruposAcesso);
        remove(panelCadastroUsuario);
        remove(panelMain);
        remove(panelConsultaEspacoFisico);
        remove(panelAlterarSenha);
        remove(panelLimparPalete);
        remove(panelLimparRua);
        remove(panelMoverProduto);
        remove(panelMoverPalete);
        remove(panelRemoverPaleteVazio);
        remove(PanelCadastroCliente);
        remove(panelCancelamentoEntrada);
        remove(panelCancelamentoSaida);
        remove(panelCadastroCargo);
        remove(panelRelatorioAparelhosAcabados);
    }

    private void analisaPermissaoMenu(){
        Map<Integer,Permissao> mapPermissoes = WMSSession.getInstance().getMapPermissoes();
        //Check permissões
        if(!mapPermissoes.containsKey(37)){mCadastro.remove(iMClientes);}
        if(!mapPermissoes.containsKey(1)){mCadastro.remove(iMFornecedores);}
        if(!mapPermissoes.containsKey(5)){mCadastro.remove(iMGruposProdutos);}
        if(!mapPermissoes.containsKey(9)){mCadastro.remove(iMPaletes);}
        if(!mapPermissoes.containsKey(13)){mCadastro.remove(iMProdutos);}
        if(!mapPermissoes.containsKey(17)){mCadastro.remove(iMRuas);}
        if(!mapPermissoes.containsKey(41)){mCadastro.remove(iMCargos);}
        if(!mapPermissoes.containsKey(21)){mAdministrar.remove(iMGruposAcessos);}
        if(!mapPermissoes.containsKey(25)){mAdministrar.remove(iMUsuarios);}
        if(!mapPermissoes.containsKey(29)){mConsulta.remove(iMEspacoFisico);}
        if(!mapPermissoes.containsKey(30)){mEstoque.remove(iMEntrada);}
        if(!mapPermissoes.containsKey(31)){mEstoque.remove(iMSaida);}

        if(!mapPermissoes.containsKey(32)){mManutencao.remove(imLimparPalete);}
        if(!mapPermissoes.containsKey(33)){mManutencao.remove(imLimparRua);}
        if(!mapPermissoes.containsKey(34)){mManutencao.remove(imMoverPalete);}
        if(!mapPermissoes.containsKey(35)){mManutencao.remove(imMoverProduto);}
        if(!mapPermissoes.containsKey(36)){mManutencao.remove(imRemoverPaleteVazio);}
        

        //Remove menu caso não exista item de menu
        if(mCadastro.getItemCount() == 0){menuBar.remove(mCadastro);}
        if(mAdministrar.getItemCount() == 0){menuBar.remove(mAdministrar);}
        if(mEstoque.getItemCount() == 0){menuBar.remove(mEstoque);}
        if(mConsulta.getItemCount() == 0){menuBar.remove(mConsulta);}

        if(mManutencao.getItemCount() == 0){mEstoque.remove(mManutencao);}
    }

    /**
     * @return the lbNotificacao
     */
    public modules.enderecamento.gui.custom.WMSLabel getLbNotificacao() {
        return lbNotificacao;
    }

    /**
     * @param lbNotificacao the lbNotificacao to set
     */
    public void setLbNotificacao(modules.enderecamento.gui.custom.WMSLabel lbNotificacao) {
        this.lbNotificacao = lbNotificacao;
    }

}
